package com.eascs.web.o2o.mq.dao;

import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Repository;

import com.eascs.app.dao.JdbcSession;
import com.eascs.app.dao.PageResult;
import com.eascs.app.dao.SqlPageQuery;
import com.eascs.app.runtime.RuntimeSetting;
import com.eascs.web.o2o.report.constants.FefundConstants;

@Repository
public class RabbitMqDao {
	@Inject
	JdbcSession jdbcSession;
	@Inject
	JdbcSession jdbcSessionForService;
	@Inject
	JdbcSession jdbcSessionForSlaveService;
	
	//service
	public <T> T findEntityForService(String sql, Class<T> requiredType, Object... params) {
		RuntimeSetting runtimeSetting = RuntimeSetting.get();
		if(runtimeSetting.getEnv().equals(FefundConstants.ENV_PROD)){
			return jdbcSessionForSlaveService.findEntity(sql, requiredType, params);//只有生产环境有主从隔离（从库只读）
		}
		return jdbcSessionForService.findEntity(sql, requiredType, params);
	}
	public <T> int insertForService(T entity) {
		return jdbcSessionForService.insert(entity);
	}
	
	//schedual
	public int execute(String insertSql,Object... params){
		return jdbcSession.execute(insertSql,params);
	}
	


}
